import { Observable } from 'rxjs/internal/Observable';
import { Response } from '../../../domain/Response';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { User } from '../../../domain/User';
import {CacheService} from '../localstorage/cache.service';
import {LOADING_MESSAGE} from '../localstorage/cache.service.namespace';


@Injectable({
  providedIn: 'root'
})
export class LoginApiService{

  constructor(private http: HttpClient, private cache: CacheService) {
  }

  public login(uname: String, pwd: String): Observable<Response<User>> {
    this.cache.set(LOADING_MESSAGE,{url:'/admin/signIn', message: '正在登录....'});
    return this.http.post<Response<User>>('/admin/signIn', {
      username: uname,
      password: pwd
    });
  }
}
